package com.zkthink.ceres.promotion.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zkthink.base.R;
import com.zkthink.base.request.PageParams;
import com.zkthink.ceres.common.annotations.IgnoreTenant;
import com.zkthink.ceres.promotion.dto.PromotionApplyInfoPageDTO;
import com.zkthink.ceres.promotion.dto.PromotionIdDTO;
import com.zkthink.ceres.promotion.entity.Promotion;
import com.zkthink.ceres.promotion.entity.PromotionApplyInfo;
import com.zkthink.ceres.promotion.service.PromotionApplyInfoService;
import com.zkthink.ceres.promotion.vo.admin.PromotionApplyInfoPageAdminVO;
import com.zkthink.security.annotation.PreAuth;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;


/**
 * <p>
 * 前端控制器 营销活动申请表
 * </p>
 *
 * @author kellen
 * @date 2020-06-16
 */
@Slf4j
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("/promotionApplyInfo")
@Api(value = "PromotionApplyInfo", tags = "营销活动申请表")
@PreAuth(replace = "promotionApplyInfo:")
public class PromotionApplyInfoController {

  private PromotionApplyInfoService promotionApplyInfoService;


  @ApiOperation("报名活动")
  @PostMapping("/applyPromotion")
  public R<Boolean> applyPromotion(@RequestBody PromotionApplyInfo info) {
    R<Boolean> applyResult = promotionApplyInfoService.applyPromotion(info);
    if (applyResult != null && applyResult.getCode() != 0) {
      return applyResult;
    }
    return R.success(true);
  }

  @ApiOperation(value = "分页列表查询")
  @PostMapping(value = "/page")
  public R<IPage<PromotionApplyInfoPageAdminVO>> page(
      @RequestBody @Validated PageParams<PromotionApplyInfoPageDTO> params) {
    return promotionApplyInfoService.page(params);
  }

  @ApiOperation("报名活动审核")
  @PostMapping("/auditPromotion")
  public R<Boolean> auditPromotion(@RequestBody PromotionApplyInfo info) {
    R<Boolean> auditResult = promotionApplyInfoService.auditPromotion(info);
    if (auditResult != null && auditResult.getCode() != 0) {
      return auditResult;
    }
    return R.success(true);
  }

  @ApiOperation("清退某个活动申请")
  @PostMapping("/closeApplyInfo")
  @IgnoreTenant
  public R<Boolean> closeApplyInfo(@RequestBody PromotionIdDTO promotionIdDTO) {
    return promotionApplyInfoService.closeApplyInfo(promotionIdDTO);
  }

}
